#include "stdafx.h"
#include "../sgp/Settings.h"
#include "../sgp/ImageManager.h"
#include "../sgp/FontManager.h"

namespace ja2{ namespace sgp
{
	FontManager::FontManager(ImageManager &ImageManager_, std::uint_least8_t DefaultPixelDepth, Settings const &Settings_, FontTranslationTablePtr_t &&pTable)
		: m_ImageManager(ImageManager_),
		m_DefaultPixelDepth(DefaultPixelDepth), 
		m_FontDestRegion(0, 0, Settings_.res_width(), 
		Settings_.res_height()),
		m_FontDestinationBPP(Settings_.m_PixelDepth), 
		m_FontDestinationPitch(0),
		m_pTranslationTable(std::move(pTable))
	{
//x		FontDefault=(-1);
//x		FontDestBuffer=BACKBUFFER;
//x		FontDestWrap=FALSE;
		// Table must be valid
		if(!m_pTranslationTable)
			throw RuntimeException("FontManager: Font translation table is empty.");
		// register the appropriate debug topics
		JA2_REGISTER_DEBUG_TOPIC(TOPIC_FONT_HANDLER, "Font Manager");
		// Initialize fonts
		m_pLarge = load(boost::filesystem::path("FONTS")/"LARGEFONT1.STI");
		m_pLarge->create_palette_tables();

		m_pSmall = load(boost::filesystem::path("FONTS")/"SMALLFONT1.STI");
		m_pSmall->create_palette_tables();

		m_pTiny = load(boost::filesystem::path("FONTS")/"TINYFONT1.STI");
		m_pTiny->create_palette_tables();

		m_pPoint12 = load(boost::filesystem::path("FONTS")/"FONT12POINT1.STI");
		m_pPoint12->create_palette_tables();

		m_pClock = load(boost::filesystem::path("FONTS")/"CLOCKFONT.STI");
		m_pClock->create_palette_tables();

		m_pComp = load(boost::filesystem::path("FONTS")/"COMPFONT.STI");
		m_pComp->create_palette_tables();

		m_pCompSmall = load(boost::filesystem::path("FONTS")/"SMALLCOMPFONT.STI");
		m_pCompSmall->create_palette_tables();

		m_pRoman10 = load(boost::filesystem::path("FONTS")/"FONT10ROMAN.STI");
		m_pRoman10->create_palette_tables();

		m_pRoman12 = load(boost::filesystem::path("FONTS")/"FONT12ROMAN.STI");
		m_pRoman12->create_palette_tables();

		m_pSans14 = load(boost::filesystem::path("FONTS")/"FONT14SANSERIF.STI");
		m_pSans14->create_palette_tables();

		m_pArial10 = load(boost::filesystem::path("FONTS")/"FONT10ARIAL.STI");
		m_pArial10->create_palette_tables();

		m_pArial14 = load(boost::filesystem::path("FONTS")/"FONT14ARIAL.STI");
		m_pArial14->create_palette_tables();

		m_pArial10Bold = load(boost::filesystem::path("FONTS")/"FONT10ARIALBOLD.STI");
		m_pArial10Bold->create_palette_tables();

		m_pArial12 = load(boost::filesystem::path("FONTS")/"FONT12ARIAL.STI");
		m_pArial12->create_palette_tables();

		m_pBlocky = load(boost::filesystem::path("FONTS")/"BLOCKFONT.STI");
		m_pBlocky->create_palette_tables();

		m_pBlocky2 = load(boost::filesystem::path("FONTS")/"BLOCKFONT2.STI");
		m_pBlocky2->create_palette_tables();

		m_pArial12Fixed = load(boost::filesystem::path("FONTS")/"FONT12ARIALFIXEDWIDTH.STI");
		m_pArial12Fixed->create_palette_tables();

		m_pArial16 = load(boost::filesystem::path("FONTS")/"FONT16ARIAL.STI");
		m_pArial16->create_palette_tables();

		m_pBlockyNarrow = load(boost::filesystem::path("FONTS")/"BLOCKFONTNARROW.STI");
		m_pBlockyNarrow->create_palette_tables();

		m_pHumanist14 = load(boost::filesystem::path("FONTS")/"FONT14HUMANIST.STI");
		m_pHumanist14->create_palette_tables();

		// Set default for font system
//x		SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE );

//x#ifdef WINFONTS
//x		InitWinFonts( );
//x#endif
	}

	FontPtr_t FontManager::load(boost::filesystem::path const &Path)
	{
		JA2_ASSERT(!Path.empty());
		// Create image
		auto video_obj = m_ImageManager.load_image(Path);
//x		if(FontDefault==(-1))
//x			FontDefault=LoadIndex;

		return FontPtr_t(new Font(video_obj));
	}
} /*sgp*/} /*ja2*/